/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package conshi;

/**
 *
 * @author ldorelli
 */
public class Vector2D {
    private double x;
    private double y;

    Vector2D(double x, double y){
        this.x = x; 
        this.y = y;
    }

    /**
     * @return the x field of the vector.
     */
    public double getX() {
        return x;
    }

    /**
     * @param x the x to set.
     */
    public void setX(double x) {
        this.x = x;
    }

    /**
     * @return the y
     */
    public double getY() {
        return y;
    }

    /**
     * @param y the y to set
     */
    public void setY(double y) {
        this.y = y;
    }

    public double dotProduct(Vector2D B){
        double dot_product;
        dot_product = B.x*x + B.y*y;
        return dot_product;
    }

    public void normalize(){
        double norm = Math.sqrt(Math.pow(x, x)+Math.pow(y, y));
        x/=norm;
        y/=norm;
    }
    /**
     * Sums two vectors.
     * @param summand the vector to be added.
     * @return an instance of Vector2D as the sum of the inputs.
     */
    public Vector2D add(Vector2D summand){
        Vector2D result = new Vector2D(x+summand.x,y+summand.y);
        return result;
    }

    public static void main(String[] args){
        Vector2D A, B;
        A = new Vector2D(4,5);
        B = new Vector2D(8,7);
        A = A.add(B);
        System.out.println(A.getX());
    }
}
